Skip to content

fix(js,ts): a standard global a module doesn't import links no other module's export - #3366

Merged
colbymchenry merged 1 commit into
mainfrom
claude/issue-3238-unimported-globals
Nov 18, 2026
Merged

colbymchenry merged 1 commit into
mainfrom
claude/issue-3238-unimported-globals

Conversation

@colbymchenry

@colbymchenry colbymchenry commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

A call to a global, parseInt(s, 10), new Response('ok'), new URL(…), structuredClone(…), in a module that neither declares nor imports the name, linked to a project export of that name in another file (exact-match, 0.9). Reproduced on 1.6.3 and 1.6.2. (1.6.3's #2801 stopped the same when the project's namesake is an interface or a type alias; a class or a function still linked.)

Root cause

isBuiltInOrExternal skips a bare JS/TS name only when it is in JS_BUILT_INS, a short list with Date and fetch but not parseInt, Response, URL, TextEncoder and the rest, so the name fell through to a project-wide match.

Fix

A new JS_STANDARD_GLOBALS lists the standard globals: ECMAScript's, the web platform's that browsers, Node, Deno and workers share (Response, URL, TextEncoder, structuredClone, …), and the browser's common constructors and functions. In the name matcher's candidate pool, and on its fuzzy single-candidate path, a call or new of one of those in a JS/TS ES module that doesn't import it takes only a candidate in scope, the reading #2736 gave type names:

  • the file's own declaration;
  • a global declaration: a script's top level (a file with no import or export) or directly inside declare global;
  • a polyfill hung on the global object: window.btoa = function btoa(…) {…}.

Otherwise the call is the runtime's and links nothing in the project. It applies only where the name is written bare at the reference (this.set(…) and new ctx.Request(…), which the extractors record by their last name, are some object's), no binding of the name holds at the call (a parameter, or a destructured one such as import('./x').then(({ URL }) => new URL(u))), the file is a module (a script shares its top level with other scripts), and the project doesn't auto-import its own exports (Nuxt, unplugin-auto-import).

Not JS_BUILT_INS itself: that list skips resolution outright, so a project's own class Event in the same file would stop linking too.

Validation

  • __tests__/js-unimported-global-calls.test.ts, red on main, green here: the issue's globals and three more, from TypeScript and JavaScript, link nothing; a same-file class, an imported function, a script polyfill, a declare global function and a window polyfill still link; a script still reaches another script's; a dynamic import's destructured export still links; a Nuxt app's auto-imported class still links.
  • A/B against the 1.6.3 source arm (147fe29, the same kernel binary), every changed edge read:
    • excalidraw −2: new ClipboardItem() twice in clipboard.ts, which linked a Window interface property in global.d.ts (the global is the DOM's);
    • vscode src/vs/base + src/vs/editor −2: a test's new File(…), the DOM's, which linked the enum member CompletionItemKind.File;
    • fastify, express, ai-chatbot and taxonomy byte-identical; flask and gin as controls.
  • Cost: the scope check runs lazily, only for a listed global's bare call with a candidate in another file.
  • Full suite: see the READY note.

Left out: the general rule

The issue proposes the import check as the general rule for any bare name, not only a list of globals. I built that first: on the A/B repos it removed only wrong edges, but it contradicts what four existing tests pin on purpose, a name match from an ES module to another module's exported function it doesn't import (esm-unexported-binding.test.ts, js-function-local-binding.test.ts, dynamic-import-binding.test.ts x2), a fallback for code whose imports the resolver can't see. Changing that policy is a decision for Colby; this PR keeps it for every name but the standard globals.

Credit

Thanks @inth3shadows for the report and the diagnosis. (PR #3279 mentions this issue but fixes #3277.)

Fixes #3238

🤖 Generated with Claude Code

@colbymchenry
colbymchenry force-pushed the claude/issue-3238-unimported-globals branch from 096c27b to 279b141 Compare November 17, 2026 23:33
@colbymchenry colbymchenry changed the title fix(js,ts): a global a module doesn't import links no other module's export fix(js,ts): a standard global a module doesn't import links no other module's export Nov 17, 2026
@colbymchenry
colbymchenry force-pushed the claude/issue-3238-unimported-globals branch 8 times, most recently from bebecfc to 312fa3e Compare November 18, 2026 10:07
…module's export

`parseInt(s, 10)` and `new Response('ok')` in a module that neither
declares nor imports the name linked to a project export of that name in
another file, exact-match. A bare name is skipped as a built-in only when it
is on a short list, which has `Date` and `fetch` but not `parseInt`,
`Response`, `URL`, `structuredClone` and the rest, so they fell through to a
project-wide match.

A call or `new` of a standard global (JS_STANDARD_GLOBALS: ECMAScript's, the
web platform's that browsers, Node, Deno and workers share, and the
browser's common constructors) in a JS/TS ES module that doesn't import it
now takes only a candidate in scope: the file's own; a global declaration,
at a script's top level or directly in `declare global`; or a polyfill hung
on the global object (`window.btoa = function btoa…`), the scope reading
PR 2736 gave type names. Only where the name is written bare (`this.set(…)`,
`new ctx.Request(…)` are some object's), no binding holds at the call (a
parameter, a dynamic import's destructured export), the file is a module
(scripts share their top level) and the project doesn't auto-import its
exports (Nuxt, unplugin-auto-import). Any other name keeps the name match as
the fallback the existing tests pin (esm-unexported-binding,
js-function-local-binding, dynamic-import-binding).

Validation:
- js-unimported-global-calls.test.ts: the issue's globals and three more, in
  TypeScript and JavaScript, link nothing; a same-file class, an import, a
  script polyfill, a `declare global` function and a `window` polyfill still
  link, a script still reaches another script's, a dynamic import's
  destructured export still links, and a Nuxt app's auto-imported class
  still links. Red on main, green here.
- A/B against the 1.6.3 source arm (147fe29, the same kernel): excalidraw
  -2 (`new ClipboardItem()` twice, the DOM's, which linked a `Window`
  interface property), vscode's src/vs/base + src/vs/editor -2 (a test's
  `new File()`, the DOM's, which linked the enum member
  `CompletionItemKind.File`), all wrong; fastify, express, ai-chatbot and
  taxonomy byte-identical; flask and gin as controls.

Fixes #3238

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant